//
//  RootVCOfTutorial.m
//  ProjectA_ManualGuest
//
//  Created by dingcong on 16/6/14.
//  Copyright © 2016年 丁聪. All rights reserved.
//

#import "RootVCOfTutorial.h"
#import "Masonry.h"
#import "PrefixHeader.pch"
#import "TittleView.h"
#import "Settings.h"
#import "RootVCOfVidio.h"
#import "RootVCOfPicText.h"
#import "FlowLayoutWithPicText.h"
@interface RootVCOfTutorial ()<UIScrollViewDelegate>
@property(nonatomic, retain)TittleView *titleView;
@property(nonatomic, retain)UIScrollView *scroll;


@end

@implementation RootVCOfTutorial

- (void)dealloc{
    
    [_scroll release];
    [_titleView release];
    [super dealloc];
    
}

- (instancetype)init{
    
    if (self = [super init])
    {
        self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"教程" image:[UIImage imageNamed:@"10.png"] tag:300];
        [self creatScroll];
    }
    return self;
}
- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = YES;
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.view.backgroundColor = [UIColor cyanColor];
    [self creatTitleView];
    
    [self ScrollConfig];
   
}

#pragma mark - 创建自定义导航栏
- (void)creatTitleView{
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    self.titleView = [[TittleView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
    
    self.titleView.backgroundColor = [UIColor colorWithRed:0.0 / 256.0f  green:208.0 / 256.0f blue:252.0 / 256.0f alpha:1];
    [self.view addSubview:self.titleView];
    
    self.titleView.arrOfTitle =  @[@"图文", @"视频"];
    [self.titleView release];
    UIView *view = [[UIView alloc]init];
    
    view.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:view];
    
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleView.mas_top).offset(37);
        make.centerX.equalTo(self.titleView.mas_centerX);
        make.height.offset(19);
        make.width.offset(1);
    }];
    [view release];
    
    
}



#pragma mark - 创建ScrollView
- (void)creatScroll
{
    self.scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49)];
    
  
    
    [self.view addSubview:self.scroll];
    [self.scroll release];
    
}


#pragma mark - ScrollConfig 嵌套tableview

- (void)ScrollConfig{
    
    self.scroll.contentSize = CGSizeMake(SCREEN_WIDTH * 2, self.scroll.frame.size.height);
    
    self.scroll.pagingEnabled = YES;
    
    self.scroll.backgroundColor = [UIColor whiteColor];
    
   
    [[NSNotificationCenter defaultCenter]addObserverForName:@"changeBackgroundColor" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
        
        self.scroll.backgroundColor = [[Settings shareSettings]color:WhiteToGray];
        self.titleView.backgroundColor = [[Settings shareSettings]color:SkyBlurToGray];
        
    }];
    
    FlowLayoutWithPicText *layout = [[FlowLayoutWithPicText alloc]init];
    RootVCOfPicText *imageText = [[RootVCOfPicText alloc]initWithCollectionViewLayout:layout];
    imageText.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, CGRectGetHeight(self.scroll.bounds));
    
    layout.itemSize = CGSizeMake((SCREEN_WIDTH - 30) / 2, 250);
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    layout.minimumInteritemSpacing = 10;
    layout.minimumLineSpacing = 10;
    
//    imageText.view.backgroundColor = [UIColor blueColor];
    [self addChildViewController:imageText];
    
    
    [self.scroll addSubview:imageText.view];
    
//    [imageText.view mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.scroll.mas_top).offset(0);
//        make.leading.equalTo(self.scroll.mas_leading).offset(0);
//        make.height.equalTo(self.scroll.mas_height);
//        make.width.equalTo(self.scroll.mas_width);
//        
//    }];
    [imageText release];
    RootVCOfVidio *vidio = [[RootVCOfVidio alloc]init];
    
//    vidio.view.backgroundColor = [UIColor purpleColor];
    self.scroll.delegate = self;
    [self addChildViewController:vidio];
    [self.scroll addSubview:vidio.view];
    
    [vidio.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(imageText.view.mas_centerY);
        make.leading.equalTo(imageText.view.mas_trailing).offset(0);
        make.height.equalTo(imageText.view.mas_height);
        make.width.equalTo(imageText.view.mas_width);
        
    }];
    
    [vidio release];
    
    
    
}

@end
